package com.accelstack.cmp.service;

import com.accelstack.cmp.entity.Disk;
import com.accelstack.cmp.repository.DiskRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * 磁盘Service
 */
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class DiskService {
    
    private final DiskRepository diskRepository;
    
    @Transactional
    public Disk create(Disk disk) {
        return diskRepository.save(disk);
    }
    
    @Transactional
    public Disk update(Disk disk) {
        return diskRepository.save(disk);
    }
    
    @Transactional
    public void deleteById(Long id) {
        diskRepository.deleteById(id);
    }
    
    public Optional<Disk> findById(Long id) {
        return diskRepository.findById(id);
    }
    
    public List<Disk> findAll() {
        return diskRepository.findAll();
    }
    
    public Page<Disk> findAll(Pageable pageable) {
        return diskRepository.findAll(pageable);
    }
    
    public List<Disk> findByServerId(Long serverId) {
        return diskRepository.findByServerId(serverId);
    }
}

